﻿function Get-TSMNode {    
    <#
        .SYNOPSIS
            Get TSM nodes
                    
        .DESCRIPTION
            The Get-TSMNode returns nodes registered on the TSM server

        .PARAMETER Node
            The node to search

        .PARAMETER Domain
            The domain to search

        .PARAMETER Type
            The node type to search

        .EXAMPLE
            Get-TSMNode

        .NOTES
            Contributors:  David Seibel
            Last Revision Date: 09/01/2015

    #>
    [CmdletBinding()]
    Param(
        [Parameter(Position=0)]
        $Node,

        [Parameter(Position=1)]
        $Domain,

        [Parameter(Position=2)]
        [ValidateSet("Client","NAS","Server")]
        $Type
    )

    $whereProps = @()
    $whereProps += [PSCustomObject]@{ "Column" = "NODE_NAME";   "Operator" = "LIKE"; "Value" = $Node }
    $whereProps += [PSCustomObject]@{ "Column" = "DOMAIN_NAME"; "Operator" = "LIKE"; "Value" = $Domain }
    $whereProps += [PSCustomObject]@{ "Column" = "NODETYPE";    "Operator" = "LIKE"; "Value" = $Type }

    $query = Format-TSMQuery -Table "NODES" -Where $whereProps -OrderBy "NODE_NAME"
    $result = Invoke-TSMCommand -Command $query

    $defaultDisplaySet = 'NODE_NAME','DOMAIN_NAME','PLATFORM_NAME'
    $typeDefinitions = @{
                        "PWSET_TIME"          = [DateTime]
                        "LASTACC_TIME"        = [DateTime]
                        "REG_TIME"            = [DateTime]
                        "INVALID_PW_COUNT"    = [Int32]
                        "LASTSESS_RECVD"      = [Int32]
                        "LASTSESS_SENT"       = [Int32]
                        "LASTSESS_DURATION"   = [Int32]
                        "LASTSESS_IDLEWAIT"   = [Int32]
                        "LASTSESS_COMMWAIT"   = [Int32]
                        "LASTSESS_MEDIAWAIT"  = [Int32]
                        "PASSEXP"             = [Int32]
						"ARCHDELETE"          = [bool]
						"BACKDELETE"          = [bool]
						"AGGREGATION"         = [bool]
						"KEEP_MP"             = [bool]
						"AUTO_FS_RENAME"      = [bool]
						"VALIDATEPROTOCOL"    = [bool]
						"SPLIT_LARGE_OBJECTS" = [bool]
						"RECOVER_DAMAGED"     = [bool]
                        }

    return Format-TSMData -Data $result -TypeDefinitions $typeDefinitions -DefaultDisplaySet $defaultDisplaySet
}